import Vue from 'vue'
import App from './App'
import router from './router'

// 引入vue-table-with-tree-grid
import TreeTable from 'vue-table-with-tree-grid'

// 完整引入elememnt-ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'

// 引入全局css
import './assets/css/global.css'

// 引入icon
import './assets/fonts/iconfont.css'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 引入axios --发请求
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// request拦截器  NProgress.start()展示进度条
axios.interceptors.request.use(config => {
  // console.log('config', config);
  NProgress.start()
  // 关闭转圈
  NProgress.configure({ showSpinner: false })
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
// response拦截器  NProgress.done()隐藏进度条
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

// 过滤器
Vue.filter('dateFormat', function (time) {
  const dt = new Date(time)
  const y = dt.getFullYear()
  // padStart 补全开头--(总共几位,补的str)
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
Vue.use(ElementUI)
Vue.use(VueQuillEditor)
Vue.component('tree-table', TreeTable)

// Vue.prototype.$message = Message
Vue.prototype.$http = axios
Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
